<%@page import="java.sql.PreparedStatement"%>
<%@page import="bit.util.ConnectionContext"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
// 한글의 처리를 위해 문자 인코딩을 UTF-8
request.setCharacterEncoding("UTF-8");

String name = request.getParameter("name");
String type = request.getParameter("type");
int health = Integer.parseInt(
		request.getParameter("health"));
int damage = Integer.parseInt(
		request.getParameter("damage"));

// SQL 쿼리 (INSERT 구문)
String sql = "INSERT INTO champ (name, type, health, damage) " +
						"VALUES (?, ?, ?, ?)";
Connection conn = ConnectionContext.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, name);
pstmt.setString(2, type);
pstmt.setInt(3, health);
pstmt.setInt(4, damage);

int count = pstmt.executeUpdate();

pstmt.close();
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>챔프 등록 처리 (DB에 등록)</title>
</head>
<body>
<%
if (count > 0) {
	// INSERT 성공
%>
	챔프 등록 성공 (<%= count %>개 데이터 삽입 성공)
<%
} else {
	// INSERT 실패
%>
	챔프 등록 실패 (DB에 데이터 삽입 실패)
<%
}
%>
<br/>
<a href="list.jsp">챔프 목록</a>
</body>
</html>